/**
 * 
 */
package com.fresh.api;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fresh.common.annotation.IgnoreAuth;
import com.fresh.entity.CreditCreateEntity;
import com.fresh.utils.HttpRequest;
import com.fresh.utils.PropertiesUtils;
import com.google.gson.Gson;

/**
 * 个人信用接口调用
 * 
 * @author 个人信用接口调用
 * @version 1.0
 * @date 2017年10月26日下午5:40:14 福乐康 Copyright© All Reserved 官方网站：www.flksh.com
 *       未经授权不得进行修改、复制、出售及商业使用
 */
@RequestMapping({ "/credit" })
@Controller
public class CreditController {
	
	
	private static final Logger log = LoggerFactory.getLogger(CreditController.class);

	@ResponseBody
	@IgnoreAuth
	@RequestMapping({ "create" })
	public String loginChsi(HttpServletRequest request,HttpServletResponse response)
			throws Exception {
		log.info("#loginChsi() 开始创建个人信用信息：{}");

		Gson gson=new Gson();
		
		//接口url
		String chsi_url = PropertiesUtils.getProperty("ssmh_url");
		String partner_code = PropertiesUtils.getProperty("partner_code");
		String partner_key = PropertiesUtils.getProperty("partner_key");
		
		//创建任务接口
		String creditCreateJson=null;
		String chsi_credit_url=chsi_url+"task.unify.create/v3";
		 Map<String, String> data = new HashMap<String, String>();
		 data.put("partner_code", partner_code);
		 data.put("partner_key", partner_key);
		 data.put("channel_type", "PBCCRC");
		 data.put("channel_code", "000011");
		 data.put("real_name", "孟祥东");
		 data.put("identity_code", "211322199001173014");
		 data.put("user_mobile", "18817421630");
		 HttpRequest httpRequest= HttpRequest.post(chsi_credit_url).form(data);
		 if (httpRequest.ok()) {
			 creditCreateJson=httpRequest.body();
			 log.info("#loginChsi() 创建个人信用返回信息：{}"+creditCreateJson);
		 }
		 
		 CreditCreateEntity creditCreateEntity=gson.fromJson(creditCreateJson, CreditCreateEntity.class);
		 System.out.println(gson.toJson(creditCreateEntity));
		return "ok";
	}
	

}
